package com.ruoyi.web.controller.system;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ruoyi.common.annotation.HasPermi;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.dao.SysPost;
import com.ruoyi.system.domain.persist.SysPostPo;
import com.ruoyi.system.domain.query.SysPostQo;
import com.ruoyi.system.domain.view.SysPostVo;
import com.ruoyi.system.domain.wrapper.query.SysPostWrapperQ;
import com.ruoyi.system.domain.wrapper.view.SysPostWrapperV;
import com.ruoyi.system.service.ISysPostService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 岗位信息Controller
 *
 * @author 尹国春
 * @date 2022-07-25
 */
@Api(value = "岗位信息", tags = {"岗位信息"})
@RestController
@RequestMapping("/system/post")
public class SysPostController extends BaseController
{
    @Autowired
    private ISysPostService sysPostService;

    /**
     * 岗位信息分页查询
     */
    @ApiOperation(value="岗位信息分页查询",notes="分页参数：pageNum,pageSize,orderByColumn(数据库字段名称),isAsc(asc|desc)")
    @HasPermi("system:post:query")
    @GetMapping("/list")
    public TableDataInfo<SysPostVo> list(SysPostQo sysPost)
    {
        IPage<SysPost> page=sysPostService.page(sysPost.getPage(),SysPostWrapperQ.getQueryWrapper(sysPost));
        return SysPostWrapperV.build().pageVO(page);
    }

    /**
     * 岗位信息导出
     */
    @ApiOperation("岗位信息导出")
    @HasPermi("system:post:query")
    @Log(title = "岗位信息导出", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysPostQo sysPost)
    {
        List<SysPost> list = sysPostService.list(SysPostWrapperQ.getQueryWrapper(sysPost));
        List<SysPostVo> voList = SysPostWrapperV.build().listVO(list);
        ExcelUtil<SysPostVo> util = new ExcelUtil<>(SysPostVo.class);
        util.exportExcel(response, voList, "岗位信息数据");
    }

    /**
     * 获取岗位信息详细信息
     */
    @ApiOperation("岗位信息信息")
    @HasPermi("system:post:query")
    @GetMapping(value = "/get/{postId}")
    public AjaxResult getInfo(@PathVariable("postId") String postId)
    {
        SysPost entity=sysPostService.getById(postId);
        return AjaxResult.success(SysPostWrapperV.build().entityVO(entity));
    }

    /**
     * 新增岗位信息
     */
    @ApiOperation("岗位信息新增")
    @HasPermi("system:post:edit")
    @Log(title = "新增岗位信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody SysPostPo sysPost)
    {
        return toAjax(sysPostService.insert(sysPost));
    }

    /**
     * 修改岗位信息
     */
    @ApiOperation("岗位信息修改")
    @HasPermi("system:post:edit")
    @Log(title = "修改岗位信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody SysPostPo sysPost)
    {
        return toAjax(sysPostService.updateById(sysPost));
    }

    /**
     * 删除岗位信息
     */
    @ApiOperation("岗位信息删除")
    @HasPermi("system:post:edit")
    @Log(title = "删除岗位信息", businessType = BusinessType.DELETE)
    @PostMapping("/delete/{postIds}")
    public AjaxResult remove(@PathVariable String[] postIds)
    {
        return toAjax(sysPostService.removeByIds(Arrays.asList(postIds)));
    }
}
